package designpattern.compoundPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * helper 类
 */
public class Observable implements QuackObservable {
    List<Observer> observers=new ArrayList<>();
    QuackObservable duck;

    public Observable(QuackObservable duck) {
        this.duck = duck;
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void notifyObservers() {
        for(Observer o:observers){
            o.update(duck);
        }
    }
}
